package com.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.entity.Post;
import com.entity.Users;
import com.entity.UsersPersonal;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.mapper.PostDao;
import com.service.PostService;
import com.service.UsersPersonalService;
import com.utils.DataResult;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import javafx.geometry.Pos;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 公司岗位表 前端控制器
 * </p>
 *
 * @author Damon
 * @since 2021-04-26
 */


@RestController
@CrossOrigin
@RequestMapping("/post")
public class PostController {
    @Autowired
    private PostService postService;
    /**//**//**//** 显示所有数据 *//**//**//**/
    @ApiOperation(value = "查找", notes = "查找", httpMethod = "GET")
    @RequestMapping("/listAll")
    public List<Post> listAll(){
        List<Post> list = postService.list();
        return list;
    }

    /**//**//**//** 所有信息实现分页查找 *//**//**//**/
    @RequestMapping("/list")
    @ApiOperation(value = "分页查找", notes = "分页查找", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "pageNum", value = "页码数", required = true, dataType = "string"),
            @ApiImplicitParam(name = "size", value = "显示数量", required = true, dataType = "string"),
    })
    public PageInfo list(String pageNum,String size){

        Post post=new Post();

        //分页插件实现分页查询 每页两条
        PageHelper.startPage(Integer.parseInt(pageNum),Integer.parseInt(size));
        List<Post> list=postService.list();
        PageInfo<Post> pageInfo=new PageInfo<Post>(list);
        return pageInfo;
    }

    /** 模糊查询获取企业信息列表 */
    @GetMapping("getcompanysinfo") // Get方法
    @ApiOperation(value = "模糊查询获取企业信息列表", notes = "模糊查询获取企业信息列表", httpMethod = "GET")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "content", value = "搜索内容", required = false, dataType = "string")})
    public DataResult getcompanysinfo(String content) {
        // 定义数据接收对象，这里调用了UserInfoDao.java层中的自定义SQL语句方法
        List<Post> post = postService.searchPost(content);
        // 判断是否存在该用户信息
        if(post != null) {
            // 成功返回数据
            return DataResult.finished().data("data", post).message("个人信息查找成功！");
        } else {
            // 失败返回数据
            return DataResult.failed().message("个人信息不存在！");
        }
    }


}

